<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>教练选择</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css"  media="all">
    <link rel="stylesheet" href="../../static/css/style.css"  media="all">
    <script type="text/javascript" src="../../static/js/jquery.min.js" ></script>
    <script src="../../layui/layui.js" charset="utf-8"></script>
    <script src="../../static/js/base.js" charset="utf-8"></script>
    <script src="../../static/js/ax.js"></script>
    <script src="../../static/js/jquery.cookie.js"></script>
    <script src="js/constant.js"></script>

    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body class="bg_w">

<div class="content-wrap" ms-controller="test">

    <div class="layui-row">
        <form class="layui-form layui-form-pane" id="from1">
            <input type="hidden" id="dataId" value="" />
            <div class="layui-row layui-form-item layui-col-space15">
                <div class="layui-col-sm5">
                    <label class="layui-form-label">教练姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" value="" class="layui-input" lay-verify="required">
                        <input type="hidden" id="coachId" >
                        <input type="hidden" id="coachName"  >
                    </div>
                </div>

                <div class="layui-col-sm5">
                    <button type="button" id="btnsearch" data-type="reload" class="layui-btn add_btn">搜索</button>
                </div>
            </div>

            <div class="layui-form-item">
                <table class="layui-hide" id="getCoach" lay-filter="coach"></table>
            </div>


            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" id="btnClose" class="layui-btn layui-btn-primary btn-left">关闭</button>
                    <button type="button" id="btnSubmit" class="layui-btn add_btn btn-left">提交</button>
                </div>
            </div>

        </form>
    </div>
</div>

</body>

<script>


    var $;
    layui.use(['layedit','form','laydate','layer','table'], function() {
        $ = layui.$;
        var form = layui.form,
            layDateTipsStartTime = layui.laydate,
            layer=layui.layer,
            table = layui.table;

        $('#btnClose').on("click", function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        });

        var tableIns = ax.VTable({
            elem : '#getCoach',
            url :schoolWebUrl+'/api/coachStudent/getCoachAll',
            id: 'getCoachReload',
            title:'教练列表',
            cols : [ [
                 {type:'radio'},
                 {field:'id', title: '序号', align: 'center'},
                 {field:'name', title: '教练姓名' , align: 'center'},
                 {field:'trainCartype', title: '培训车型', align: 'center'},
                 {field:'phone', title: '手机号码', align: 'center'}
            ] ]
        });

        coachPersion = {
            reload : function() {
                //执行重载
                initTable();
            }
        };
        $('#btnsearch').on('click', function(){
            var type = $(this).data('type');//获取reload
            coachPersion[type] ? coachPersion[type].call(this) : '';
        });

        var initTable=function () {
            table.reload('getCoachReload', {
                page : {
                    curr: 1 //重新从第 1 页开始
                },
                where : {
                    name : $('#name').val(),
                }
            });
        }

        $('#btnSubmit').on('click', function(obj){
            var checkStatus = table.checkStatus('getCoachReload');
             var   data = checkStatus.data;
            if(data.length>1){
                layer.alert("只能选择一个教练");
                return;
            }
            var postData={
                "id":data[0].id,
                "name" : data[0].name
            };
            console.log(postData)
            // parent.GetValue(postData); //GetValue是父界面的Js 方法
            // parent.document.getElementById("caochdata").value = JSON.stringify(postData);
            // parent.$("#caochdata").val();
            // top[top.getActiveTab().attr("name")].$('#caochdata').val()
            $(parent.document).find('#caochdata').val(JSON.stringify(postData))

            // console.log()
            // topFrame.find('#caochdata').val();
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);

        });


    });
</script>
</html>